using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using UnityEngine.Events;

public class ResourceLoadManager : SingletonPattern<ResourceLoadManager>
{
    public T Load<T>(string name) where T:Object
    {
        T resource = Resources.Load<T>(name);
        return resource;
    }

    public void LoadAsync<T>(string name,UnityAction<T> callBack) where T : Object
    {
        PublicMonoManager.Instance.StartCoroutine(RealLoadAsync<T>(name,callBack));
    }

    private IEnumerator RealLoadAsync<T>(string name, UnityAction<T> callBack) where T:Object
    {
        ResourceRequest resourceRequest = Resources.LoadAsync<T>(name);
        yield return resourceRequest;

        callBack(resourceRequest.asset as T);
    }
}
